// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'lib-flexible'
import './assets/iconfont/iconfont.css'
import 'vant/lib/icon/local.css'
import axios from 'axios'

import store from './store/index'
import jquery from 'jquery'
//返回
import Mui from 'vue-awesome-mui';
Vue.use(Mui);

//引入时间格式化
import moment from 'moment'
window.nowHref = "http://103.112.28.230:8080/endless"
import { Toast } from "vant"

Vue.prototype.$http = axios
Vue.config.productionTip = false

import { Actionsheet } from 'vant';
Vue.use(Actionsheet);

// 注册全局钩子用来拦截导航
router.beforeEach((to, from, next) => {
    const token = store.state.token ? store.state.token : window.sessionStorage.getItem("token");
    if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
        if (token) { // 通过vuex state获取当前的token是否存在
            console.log(token)
            next()
        } else {
            Toast.success("该页面需要登陆");
            next({
                path: '/login',
            })
        }
    } else {
        next()
    }
})

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    components: { App },
    template: '<App/>'
})